<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<title>{echo admin_title()}</title>
<!--header-->
{template _:header}
</head>
<body>
<div class="layui-layout layui-layout-admin">
<!--top-->
{template _main_top}
<!--nav-->
{template _main_nav}
	<div class="position">
		<h1>员工列表</h1>
	</div>
	<div class="layui-body admin-body">
		<div class="admin-content">
			<div class="searcher">
				<div class="right"><button type="button" class="layui-btn layui-add">添加店员</button></div>
				<form name="sch_form" id="sch_form" method="get" action="{echo \befen\get_url()}">
					<div class="layui-input-inline">
						<input type="text" name="store_name" id="store_name" class="layui-input" value="{echo input('param.store_name')}" placeholder="门店名称">
					</div>
					<div class="layui-input-inline"><input type="text" name="wd" id="wd" class="layui-input" value="{echo input('param.wd')}" placeholder="姓名或电话"></div>
					<div class="layui-input-inline layui-left-margin"><button type="submit" id="search" class="layui-btn">查询</button></div>
				</form>
				<div class="clear"></div>
			</div>
			<form name="theform" id="theform" method="post" action="{echo \befen\get_url()}">
			<table class="layui-table">
				<thead>
					<tr>
						<th>员工ID</th>
						<th>所属门店</th>
						<th>店员姓名</th>
						<th>联系电话</th>
						<th>角色</th>
						<th>状态</th>
						<th>微信绑定</th>
						<th>管理操作</th>
					</tr>
				</thead>
				<tbody>
					<!--{loop $list $key $val}-->
					<tr id="">
						<td>{$val[person_id]}</td>
						<td><!--{if $val['store_name']}-->{$val[store_name]}<!--{else}-->{$val[merchant_name]}<!--{/if}--></td>
						<td>{$val[per_name]}</td>
						<td>{$val[per_phone]}</td>
						<td><span class="layui-badge layui-bg-gray">{echo model('StorePerson')->getManager()[$val[manager]]}</span></td>
						<td><span class="layui-badge layui-bg-status-{$val[status]}">{echo model('StorePerson')->getStatus()[$val[status]]}</span></td>
						<td id="weixin_{$val[person_id]}"><!--{if $val['openid']}--><!--{if $val['nickname']}-->{$val[nickname]}<!--{else}-->是<!--{/if}--><!--{else}-->-<!--{/if}--></td>
						<td class="op">
							<a op="detail" lay-url="{echo url('person/detail', ['person_id' => $val['person_id']])}" class="layui-btn layui-btn-xs layui-btn-normal">员工详情</a>
							<a op="passwd" lay-url="{echo url('person/passwd', ['person_id' => $val['person_id']])}" class="layui-btn layui-btn-xs layui-btn-normal">重置密码</a>
							<!--{if !$val['openid']}-->
							<a op="bind_wechat" person_id="{$val[person_id]}" per_name="{$val[per_name]}" lay-url="{echo url('person/bind_wechat', ['person_id' => $val['person_id']])}" class="layui-btn layui-btn-xs layui-btn-normal">绑定微信</a>
							<!--{else}-->
							<a op="unbind_wechat" person_id="{$val[person_id]}" per_name="{$val[per_name]}" lay-url="{echo url('person/unbind_wechat', ['person_id' => $val['person_id']])}" class="layui-btn layui-btn-xs layui-btn-normal">解绑微信</a>
							<!--{/if}-->
						</td>
					</tr>
					<!--{/loop}-->
				</tbody>
			</table>
			</form>
			<div class="listpages">{$pagenav}</div>
		</div>
	</div>
</div>
<!--footer-->
{template _:footer}
<script type="text/javascript">
$(".layui-add").click(function(){	
	showWindow('添加店员', "{echo url('person/add', ['store_id' => input('param.store_id')])}", '600px');
});
$("a[op=detail]").click(function(){
	showWindow('店员详情', $(this).attr('lay-url'), '600px');
});
$("a[op=passwd]").click(function(){
	showWindow('重置密码', $(this).attr('lay-url'), '300px');
});
$("a[op=bind_wechat]").click(function(){
	var person_id = $(this).attr('person_id');
	var per_name = $(this).attr('per_name');
	$.ajax({
		type: "POST",
		dataType: "html",
		timeout: 30000,
		url: $(this).attr('lay-url'),
		data: {
			ajax: "html",
			person_id: person_id,
		},
		success: function(html){
			init_Layer(function(){
				layer.open({
					title: '微信绑定 - ' + per_name,
					shade: 0.5,
					isOutAnim: true,
					content: '<div style="text-align:center"><div id="bind_wechat_qrcode" style="width:250px;height:250px;margin:0 auto 1em;"></div></div>',
					btn: false
				});
				var qrcode = new QRCode(document.getElementById("bind_wechat_qrcode"), {
					width: 250,
					height: 250
				});
				qrcode.makeCode(html);
			});
		},
		complete: function(){
			hideLoader();
		},
		beforeSend: function(){
			showLoader();
		}
	});
});
$("a[op=unbind_wechat]").click(function(){
	var person_id = $(this).attr('person_id');
	op("确认要解绑吗？", $(this).attr('lay-url'), function(){
		reload();
	});
});
$('#sch_form input[name=store_name]').autoComplete({
	url: "{echo url('store/index')}",
	field: "",
	value: "{echo input('param.store_name')}",
	name_hidden: "store_id",
	value_hidden: "{echo input('param.store_id')}",
});
</script>
</body>
</html>